﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using SyncCommon;
using HefaSyncTool.Controls;
using System.Security.Permissions;

namespace HefaSyncTool
{
    [PermissionSet(SecurityAction.Demand, Name = "FullTrust")]
    [System.Runtime.InteropServices.ComVisibleAttribute(true)]
    public partial class WebEditForm : Form, IBrowserForm
    {
        public WebEditForm()
        {
            InitializeComponent();
            
        }

        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
            HefaWebBrowser.ProgressChanged += new WebBrowserProgressChangedEventHandler(HefaWebBrowser_ProgressChanged);
            //HefaWebBrowser.StartNewWindow += new EventHandler<HefaSyncTool.Controls.BrowserExtendedNavigatingEventArgs>(HefaWebBrowser_StartNewWindow);
        }

        void HefaWebBrowser_StartNewWindow(object sender, Controls.BrowserExtendedNavigatingEventArgs e)
        {
          
        }

        void HefaWebBrowser_ProgressChanged(object sender, WebBrowserProgressChangedEventArgs e)
        {
            try
            {
                progressBar1.Visible = true;
                if ((e.CurrentProgress > 0) && (e.MaximumProgress > 0))
                {
                    progressBar1.Maximum = Convert.ToInt32(e.MaximumProgress);
                    progressBar1.Step = Convert.ToInt32(e.CurrentProgress);
                    progressBar1.PerformStep();
                }
                else if (HefaWebBrowser.ReadyState == WebBrowserReadyState.Complete)
                {
                    progressBar1.Value = 0;
                    progressBar1.Visible = false;
                }
            }
            catch
            { }
            
            //if (HefaWebBrowser.ReadyState == WebBrowserReadyState.Complete)
        }

        private void btnBack_Click(object sender, EventArgs e)
        {
            HefaWebBrowser.GoBack();
        }

        private void btnHead_Click(object sender, EventArgs e)
        {
            HefaWebBrowser.GoForward();
        }

        public void ShowLoading()
        {
            //this.maskPanel1.Visible = true;
        }

        public void StopLoading()
        {
            //this.maskPanel1.Visible = false;
        }
    }
}
